package hengtiansoft.com.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.DatePicker;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DatePickerTest extends BaseActivity {
    android.widget.DatePicker datePicker;
    TextView textView;
    Calendar calendar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_date_picker);
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initView() {
        textView = (TextView) findViewById(R.id.textView13);
        datePicker = (android.widget.DatePicker) findViewById(R.id.datePickers);
        String time = new SimpleDateFormat("yyyy/mm/dd").format(Calendar.getInstance().getTime());
        textView.setText(time);
    }

    @Override
    public void initData() {
//        Date date = new Date(System.currentTimeMillis());
        Calendar c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH);
        Log.e("month", String.valueOf(month));
        int data = c.get(Calendar.DATE);

        datePicker.init(year, month, data, new DatePicker.OnDateChangedListener() {
            @Override
            public void onDateChanged(DatePicker datePicker, int i, int i1, int i2) {
                calendar = Calendar.getInstance();
//                calendar.set(1991, 11, 3);
                calendar.set(i, i1, i2);
                calendar.getTime().toString();
                textView.setText(
                        String.valueOf(i1+1) + "/" + String.valueOf(i2) + "/" + String.valueOf(i));
            }
        });
    }


}
